<html>
<head>
<title>Scilab 4.1</title>
<style type="text/css">
</head>
<body>
<div>scilab</div>
<div>comandos</div>
<div>input</div>
<?php
if (isset($_POST['comandos']))
{
    $descriptorspec = array(
            0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
            1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
            2 => array("file", "/home/projetos/anaweb/scilab/error-output.txt", "a") // stderr is a file to write to
            );

    $cwd = '/home/projetos/anaweb/scilab';
    $env = array('HOME' => '/home/projetos/anaweb/scilab','DISPLAY' => '0');

    //$process = proc_open('scilab -nwni -f /home/projetos/anaweb/scilab/teste.sci', $descriptorspec, $pipes, $cwd, $env);
    $process = proc_open('scilab -nogui', $descriptorspec, $pipes, $cwd, $env);

    if (is_resource($process)) {
        // $pipes now looks like this:
        // 0 => writeable handle connected to child stdin
        // 1 => readable handle connected to child stdout
        // Any error output will be appended to /tmp/error-output.txt
        $i=0;
        while (isset($_POST["comandos"][$i++]))
            fwrite($pipes[0],$_POST["comandos"][$i]);
        fclose($pipes[0]);
        echo "<pre>\n";	
        echo stream_get_contents($pipes[1]);
        echo "\n</pre>\n";
        fclose($pipes[1]);

        // It is important that you close any pipes before calling
        // proc_close in order to avoid a deadlock
        $return_value = proc_close($process);
    }
}
?>
</body>
</html>
